home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Demos / Extend 3.0 Demo / Demo Libraries / Demo Generic Lib / Demo Generic Lib.rsrc / MODL_5369_Divide < prev    next >
Encoding:
Text File  |  1994-06-22  |  2.0 KB  |  85 lines

  1. integer valid1,valid2,valid3;
  2. real    timeArray[];
  3.  
  4. **     This block divides the top input by the bottom.
  5. **    Copyright © 1989-1992 by Imagine That, Inc.
  6. **    All Rights Reserved.
  7. **    Extend Generic Library, Divide block; Alfy Riddle
  8. **        modified     1/1/92 JSL modified for V2.0
  9.  
  10. procedure calc()
  11. {
  12.     ** check for divide by zero only.  Don't check for NaN
  13.     if( Con2In == 0.0 AND stopIt )
  14.         {
  15.         userError("Divide by zero in Divide, block number "+(MyBlockNumber()));
  16.         abort;
  17.         }
  18.  
  19.     ConOut = Con1In / Con2In;
  20.  
  21.     ** sysGlobal2 is the file reference number for the DEBUG TRACE
  22.     if( sysGlobal2 != 0.0 )    ** 0 is error, check for open file for TRACE
  23.         {
  24.         fileWrite(sysGlobal2,"Divide block number "+(MyBlockNumber()),"",True);
  25.         fileWrite(sysGlobal2,"Top Input = "+con1In,"",True);
  26.         fileWrite(sysGlobal2,"Bottom Input = "+con2In,"",True);
  27.         fileWrite(sysGlobal2,"Output = "+conOut,"",True);
  28.         fileWrite(sysGlobal2," ","",True);
  29.         }
  30. }
  31.  
  32.  
  33. ** This message occurs for each step in the simulation.
  34. on Simulate
  35. {
  36.     calc();
  37. }
  38.  
  39.  
  40. on endSim
  41. {
  42.     ** sysGlobal1 is the file reference number for the TEXT REPORT
  43.     if( sysGlobal1 != 0.0 )  ** 0 is error, check for open file for REPORT
  44.         {
  45.         fileWrite(sysGlobal1,"Divide block number "+(MyBlockNumber()),"",True);
  46.         if( stopIt )
  47.             fileWrite(sysGlobal1,"Stops simulation on divide by zero","",True);
  48.         else
  49.             fileWrite(sysGlobal1,"Outputs a noValue on divide by zero","",True);
  50.         if( comments != "" )
  51.             fileWrite(sysGlobal1,"Comments = "+comments,"",True);        
  52.         fileWrite(sysGlobal1," ","",True);
  53.         }
  54. }
  55.  
  56.  
  57. ** If the dialog data is inconsistent for simulation, abort.
  58. on checkData
  59. {
  60.     sysGlobal1 = 0.0;    ** prevent false reports
  61.     sysGlobal2 = 0.0;    ** prevent false debugs
  62.     
  63.     valid1 = Con1In;    ** 1 if connected, 0 if not
  64.     valid2 = Con2In;    ** 1 if connected, 0 if not
  65.  
  66.     if( valid1 + valid2 < 2 )
  67.         {
  68.         userError("Both Connectors must be used in Divide, block number "+(MyBlockNumber()));
  69.         abort;
  70.         }
  71. }
  72.  
  73.  
  74. ** Initialize any simulation variables.
  75. on initSim
  76. {
  77.     if( getPassedArray(sysGlobal0, timeArray) )
  78.         getSimulateMsgs(FALSE);
  79. }
  80.  
  81.  
  82. on createBlock
  83. {
  84.     putNaN = TRUE;
  85. }